//引入
import {JSEncrypt} from 'jsencrypt'

/**
 * 加密
 * @param {String}  需要加密的参数
 */
export function passwordEncryption(param) {
    // 后台给的公钥
    let publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/cgLwNkDEky03dSy+yM0fr+MU' +
        'BTp1zgZ4PfNmNdR4+j5aeYHRvzyuvCq6mYaTmdGBnDtOsBT9796XTeV0FyIQeFGR' +
        'HLxZ+XxTSLT7NmIC+7uDy/2tUYBFnI7y0VT+6fLyyiFBG3p2pBy3X7cz0y/IxK3c' +
        '+B3fmnpY06Vq9/SROQIDAQAB'
    let encryptor = new JSEncrypt() // 新建JSEncrypt对象
    encryptor.setPublicKey(publicKey) // 设置公钥
    let passwordEncryp = encryptor.encrypt(param) // 对密码进行加密
    return passwordEncryp
}

// 解密
export function decrypt(msg) {
    const privateKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAL9yAvA2QMSTLTd1' +
        'LL7IzR+v4xQFOnXOBng982Y11Hj6Plp5gdG/PK68KrqZhpOZ0YGcO06wFP3v3pdN' +
        '5XQXIhB4UZEcvFn5fFNItPs2YgL7u4PL/a1RgEWcjvLRVP7p8vLKIUEbenakHLdf' +
        'tzPTL8jErdz4Hd+aeljTpWr39JE5AgMBAAECgYAH/snyoEFqND9SLpmUyiwO47iX' +
        'EHTVkKoigWvV2++oscLC4ooyaUsufPtH2buOFIF0aULs0Vu/EzJ3nTA0/fZVKUHx' +
        'fxHI5Zk7cB/zCReyN3FqpkmLwfLsbUBnIVwLRRVlQJ9v/NZ+hGklYDKs7XEmqI1K' +
        '7ktbVvxjbZkVQ+DyAQJBAOMGjUf5jdX5yjkjRzt+GjRQtvwYrtNVw6BUkz5t++eF' +
        '4V1EDmDd8vjTze/uQ0Z5vwfgYv2N9WotEOBmtO04vXkCQQDX4PizEA8SkX9MzA18' +
        'vUBQGnJMvix2/msllegPkM8WMVzPqfp9ZUvuqP2Dm/BCEHmhft0Ro09z86M9Xm5+' +
        'IkHBAkBR7A5VV58wBKhNgAZ3WGTaVfoB9GI5zqv+EibkE0ogXLZbMnDB0bWYxs18' +
        'dA0AxHQDwpvWBUD25HY/k7BcHep5AkEAooXJVi2B223UU8HPaZik4Wl3oZUOrqsN' +
        'iWdZJNbVQRT6lZCXd24ag1uQOFPexi3XFCEJV60GNPo4bAw6zRUHQQJAShwuV//C' +
        'qFKEuMmnzLXZwBrbZCAJF3askYoCZQXtzbxel8M+a8ce+hXSdzGtq6QUqTzpe6Jc' +
        'qPeFVmkBBERolA=='
    let decrypt = new JSEncrypt()
    decrypt.setPrivateKey(privateKey)
    var decryptMsg = decrypt.decrypt(msg)
    return decryptMsg
}
